package com.ruoyi.web.controller.byw;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BywStage;
import com.ruoyi.system.service.IBywStageService;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 达人基础Controller
 *
 * @author ruoyi
 * @date 2024-05-25
 */
@Api(tags = {"达人基础"})
@RestController
@RequestMapping("/byw/stage")
public class BywStageController extends BaseController
{
    @Autowired
    private IBywStageService bywStageService;

    @Autowired
    private ISysUserService userService;

    @ApiOperation("小程序下拉数据")
    @GetMapping("/xcxDownList")
    public List<Map<String, String>>  xcxListQuery(){
        List<SysUser>  userList =  userService.selectApcUserList();
        List<Map<String, String>> xcxList = Lists.newArrayList();
        Map<String, String> map = null;
        if(userList.size() > 0){
            for(SysUser sysUser : userList){
                map = new HashMap<>();
                map.put("xcxAppid",sysUser.getTiktokAppid());
                map.put("xcxName",sysUser.getTiktokName());
                xcxList.add(map);
            }

        }

        return xcxList;
    }



    /**
     * 查询达人基础列表
     */
    @ApiOperation("查询达人基础列表")
    @PreAuthorize("@ss.hasPermi('byw:stage:list')")
    @GetMapping("/list")
    public TableDataInfo list(BywStage bywStage)
    {
        startPage();
        List<BywStage> list = bywStageService.selectBywStageList(bywStage);
        return getDataTable(list);
    }

    /**
     * 导出达人基础列表
     */

    @PreAuthorize("@ss.hasPermi('byw:stage:export')")
    @Log(title = "达人基础", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BywStage bywStage)
    {
        List<BywStage> list = bywStageService.selectBywStageList(bywStage);
        ExcelUtil<BywStage> util = new ExcelUtil<BywStage>(BywStage.class);
        util.exportExcel(response, list, "达人基础数据");
    }

    /**
     * 获取达人基础详细信息
     */
    @ApiOperation("获取达人基础详细信息")
    @PreAuthorize("@ss.hasPermi('byw:stage:query')")
    @GetMapping(value = "/{stageId}")
    public AjaxResult getInfo(@PathVariable("stageId") Long stageId)
    {
        return success(bywStageService.selectBywStageByStageId(stageId));
    }

    /**
     * 新增达人基础
     */
    @PreAuthorize("@ss.hasPermi('byw:stage:add')")
    @Log(title = "达人基础", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BywStage bywStage)
    {
        return toAjax(bywStageService.insertBywStage(bywStage));
    }

    /**
     * 修改达人基础
     */
    @PreAuthorize("@ss.hasPermi('byw:stage:edit')")
    @Log(title = "达人基础", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BywStage bywStage)
    {
        return toAjax(bywStageService.updateBywStage(bywStage));
    }

    /**
     * 删除达人基础
     */
    @PreAuthorize("@ss.hasPermi('byw:stage:remove')")
    @Log(title = "达人基础", businessType = BusinessType.DELETE)
    @DeleteMapping("/{stageIds}")
    public AjaxResult remove(@PathVariable Long[] stageIds)
    {
        return toAjax(bywStageService.deleteBywStageByStageIds(stageIds));
    }
}
